import { Button, Tooltip } from 'antd';

import pageStyles from '@/common/pageLayout.less';
import { PlusCircleOutlined, DeleteOutlined } from '@ant-design/icons';

import { ColumnsRenderFun, DictionaryRenderFun, formatDecimal, getSorter } from '../../Acommon';

/**
 * @getBidColumns 采购人代表表格配置列表
 * @returns
 */
export const getBidColumns = ({ onRemove, onOpen, isShowOpenBtn }: any): Record<string, any>[] => {
  const columnsList = [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      visible: true,
      width: 80,
      fixed: 'left',
      render: (_: string, __: Record<string, any>, index: string) => index + 1,
    },
    {
      title: '姓名',
      dataIndex: 'fullName',
      key: 'fullName',
      visible: true,
      width: 170,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '现任职务',
      dataIndex: 'positionName',
      key: 'positionName',
      visible: true,
      width: 170,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '联系电话',
      dataIndex: 'phoneMobile',
      key: 'phoneMobile',
      visible: true,
      width: 180,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '熟悉有关法规',
      dataIndex: 'lawFlag',
      key: 'lawFlag',
      visible: true,
      width: 180,
      render: (text: string) => {
        return (
          <>
            <span>{Number(text) == 0 ? '否' : Number(text) == 1 ? '是' : '--'}</span>
          </>
        );
      },
    },
    {
      title: '同类评标经历',
      dataIndex: 'experFlag',
      key: 'experFlag',
      visible: true,
      width: 180,
      render: (text: string) => {
        return (
          <>
            <span>{Number(text) == 0 ? '否' : Number(text) == 1 ? '是' : '--'}</span>
          </>
        );
      },
    },
    {
      title: (
        <div style={{ textAlign: 'center' }}>
          <Button type={'link'} size={'small'} icon={<PlusCircleOutlined />} className="manageBtntTxtStyle" onClick={() => onOpen()}>
            添加
          </Button>
        </div>
      ),
      dataIndex: 'operation',
      key: 'operation',
      width: 100,
      visible: true,
      unDrag: true,
      align: 'left',
      fixed: 'right',
      render: (_: string, Record: Record<string, any>, index: number) => {
        return (
          <div style={{ textAlign: 'center' }}>
            <Button
              type={'link'}
              size={'small'}
              danger
              className={'manageBtntTxtStyle manageColorRedBtn'}
              icon={<DeleteOutlined />}
              onClick={() => {
                onRemove(Record, index);
              }}
            >
              删除
            </Button>
          </div>
        );
      },
    },
  ];

  if (isShowOpenBtn) {
    return columnsList;
  } else {
    return columnsList?.filter((item) => item?.key != 'operation');
  }
};

/**
 * @getBidColumns 评标专家表格配置列表
 * @returns
 */
export const getExpertsColumns = ({ onRemove, onOpen, isShowOpenBtn }: any): Record<string, any>[] => {
  const columnsList = [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      visible: true,
      width: 80,
      fixed: 'left',
      render: (_: string, __: Record<string, any>, index: string) => index + 1,
    },
    {
      title: '姓名',
      dataIndex: 'fullName',
      key: 'fullName',
      visible: true,
      width: 170,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '工作单位',
      dataIndex: 'companyName',
      key: 'companyName',
      visible: true,
      width: 170,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '职务',
      dataIndex: 'positionName',
      key: 'positionName',
      visible: true,
      width: 180,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '职称',
      dataIndex: 'titleTech',
      key: 'titleTech',
      visible: true,
      width: 180,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '联系方式',
      dataIndex: 'phoneMobile',
      key: 'phoneMobile',
      visible: true,
      width: 180,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: (
        <div style={{ textAlign: 'center' }}>
          <Button type={'link'} size={'small'} icon={<PlusCircleOutlined />} className="manageBtntTxtStyle" onClick={() => onOpen()}>
            选择
          </Button>
        </div>
      ),
      dataIndex: 'operation',
      key: 'operation',
      width: 100,
      visible: true,
      unDrag: true,
      align: 'left',
      fixed: 'right',
      render: (_: string, record: Record<string, any>, index: number) => {
        return (
          <div style={{ textAlign: 'center' }}>
            <Button
              type={'link'}
              size={'small'}
              danger
              className={'manageBtntTxtStyle manageColorRedBtn'}
              icon={<DeleteOutlined />}
              onClick={() => {
                onRemove(record, index);
              }}
            >
              删除
            </Button>
          </div>
        );
      },
    },
  ];

  if (isShowOpenBtn) {
    return columnsList;
  } else {
    return columnsList?.filter((item) => item?.key != 'operation');
  }
};

/**
 * @SelectExpertsColumns 弹窗专家表格配置列表
 * @returns
 */
export const getSelectExpertsColumns = (): Record<string, any>[] => {
  return [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      visible: true,
      width: 50,
      fixed: 'left',
      render: (_: string, __: Record<string, any>, index: string) => index + 1,
    },
    {
      title: '姓名',
      dataIndex: 'fullName',
      key: 'fullName',
      visible: true,
      width: 80,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '工作单位',
      dataIndex: 'companyName',
      key: 'companyName',
      visible: true,
      width: 100,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '职务',
      dataIndex: 'positionName', // 当前职位
      key: 'positionName',
      visible: true,
      width: 100,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '职称',
      dataIndex: 'titleTech', // 技术职称
      key: 'titleTech',
      visible: true,
      width: 100,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '联系方式',
      dataIndex: 'phoneMobile', // 常用手机
      key: 'phoneMobile',
      visible: true,
      width: 100,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
  ];
};

/**
 * @getProjectTableColumns 步骤条第一步 项目弹窗配置
 */
export const getProjectTableColumns = (): Record<string, any>[] => {
  return [
    {
      title: '采购项目名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.applyTitle, b?.applyTitle),
      width: 220,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '包号',
      dataIndex: 'packCode',
      key: 'packCode',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => getSorter(a?.packCode, b?.packCode),
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '标包名称',
      dataIndex: 'packName',
      key: 'packName',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.packName, b?.packName),
      width: 170,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '采购类别',
      dataIndex: 'supplyWay',
      key: 'supplyWay',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.supplyWay, b?.supplyWay),
      width: 140,
      render: (text: number) => {
        return text == 0 ? '月度计划' : text == 1 ? '零星采购' : text == 2 ? '实验平台' : '--';
      },
    },
    {
      title: '拟采用采购方式',
      dataIndex: 'procureRealName',
      key: 'procureRealName',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.procureRealName, b?.procureRealName),
      width: 180,
      render: (text: string) => DictionaryRenderFun({ text }),
    },
  ];
};

export const IntentProjectColumns = (): Record<string, any>[] => {
  return [
    {
      title: '申请标题',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      visible: true,
      width: 280,
      fixed: 'left',
      sorter: (a: any, b: any) => getSorter(a?.applyTitle, b?.applyTitle),
      render: (text: string, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '标的来源',
      dataIndex: 'supplyWay',
      key: 'supplyWay',
      visible: true,
      // fixed: 'left',
      sorter: (a: any, b: any) => getSorter(a?.supplyWay, b?.supplyWay),
      width: 160,
      render: (text: string) => {
        return (
          <Tooltip>
            <span className={pageStyles['over-flow-hidden']}>{text == '0' ? '月度计划' : text == '1' ? '零星采购' : text == '2' ? '实验平台' : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '承办部门/团队',
      dataIndex: 'applyDepartmentName',
      key: 'applyDepartmentName',
      width: 170,
      visible: true,
      // fixed: 'left',
      sorter: (a: any, b: any) => getSorter(a?.applyDepartmentID, b?.applyDepartmentID),
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },

    {
      title: '预估总价(元)',
      dataIndex: 'expectSum',
      key: 'expectSum',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.expectSum, b?.expectSum),
      width: 150,
      render: (text: number) => <span>{formatDecimal(text)}</span>,
    },
    {
      title: '联系人',
      dataIndex: 'createrName',
      key: 'createrName',
      sorter: (a: any, b: any) => getSorter(a?.createrName, b?.createrName),
      visible: true,
      width: 150,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '联系电话',
      dataIndex: 'contactMobile',
      key: 'contactMobile',
      sorter: (a: any, b: any) => getSorter(a?.contactMobile, b?.contactMobile),
      visible: true,
      width: 150,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
  ];
};
